﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.SIESystemManager.Calculate
{
    public class C_D37
    {
        public double GetD37(DataRow[] dr1, DataRow[] dr2,string Routing)
        {
            double TclearHour=0;
            double TD37 = 0, Tw1 = 0, Tw2 = 0, Td1 = 0, Td2 = 0, SngH = 0, SngP = 0, SngF = 0;
            double TD37_Wash_Brush_Board = 0;//D37_装洗毛刷板
            double TD37_Drilling_Hinge = 0;//D37_钻装合页铰
            double TD37_Mounted_Countertop_Flat_Hinge = 0;//D37_装台面平铰
            double TD37_Copper_Head_Rubber_Plug = 0;//D37_打铜头胶塞
            double TD37_Twisted_Tooth_Nut = 0;//D37_拧带齿螺母
            double TD37_Decorative_Hole_Cover = 0;//D37_装装饰孔盖
            double TD37_LOGO = 0;//D37_贴美时LOGO

            //单位工时
            double WD37_Wash_Brush_Board = 0;//D37_装洗毛刷板
            double WD37_Drilling_Hinge = 0;//D37_钻装合页铰
            double WD37_Mounted_Countertop_Flat_Hinge = 0;//D37_装台面平铰
            double WD37_Copper_Head_Rubber_Plug = 0;//D37_打铜头胶塞
            double WD37_Twisted_Tooth_Nut = 0;//D37_拧带齿螺母
            double WD37_Decorative_Hole_Cover = 0;//D37_装装饰孔盖
            double WD37_LOGO = 0;//D37_贴美时LOGO

            //附加工时
            double AD37_Wash_Brush_Board = 0;//D37_装洗毛刷板
            double AD37_Drilling_Hinge = 0;//D37_钻装合页铰
            double AD37_Mounted_Countertop_Flat_Hinge = 0;//D37_装台面平铰
            double AD37_Copper_Head_Rubber_Plug = 0;//D37_打铜头胶塞
            double AD37_Twisted_Tooth_Nut = 0;//D37_拧带齿螺母
            double AD37_Decorative_Hole_Cover = 0;//D37_装装饰孔盖
            double AD37_LOGO = 0;//D37_贴美时LOGO

            //获取输入n值
            foreach (var drData in dr1)
            {
                TD37_Wash_Brush_Board = double.Parse(string.IsNullOrEmpty(drData["D37_Wash_Brush_Board"].ToString()) ? "0" : drData["D37_Wash_Brush_Board"].ToString());//装洗毛刷板
                TD37_Drilling_Hinge = double.Parse(string.IsNullOrEmpty(drData["D37_Drilling_Hinge"].ToString()) ? "0" : drData["D37_Drilling_Hinge"].ToString());//钻装合页铰
                TD37_Mounted_Countertop_Flat_Hinge = double.Parse(string.IsNullOrEmpty(drData["D37_Mounted_Countertop_Flat_Hinge"].ToString()) ? "0" : drData["D37_Mounted_Countertop_Flat_Hinge"].ToString());//装台面平铰
                TD37_Copper_Head_Rubber_Plug = double.Parse(string.IsNullOrEmpty(drData["D37_Copper_Head_Rubber_Plug"].ToString()) ? "0" : drData["D37_Copper_Head_Rubber_Plug"].ToString());//装台面平铰

                TD37_Twisted_Tooth_Nut = double.Parse(string.IsNullOrEmpty(drData["D37_Twisted_Tooth_Nut"].ToString()) ? "0" : drData["D37_Twisted_Tooth_Nut"].ToString());//装台面平铰
                TD37_Decorative_Hole_Cover = double.Parse(string.IsNullOrEmpty(drData["D37_Decorative_Hole_Cover"].ToString()) ? "0" : drData["D37_Decorative_Hole_Cover"].ToString());//装台面平铰
                TD37_LOGO = double.Parse(string.IsNullOrEmpty(drData["D37_LOGO"].ToString()) ? "0" : drData["D37_LOGO"].ToString());//装台面平铰

                Tw1 = double.Parse(string.IsNullOrEmpty(drData["Width_1"].ToString().Replace("*", "")) ? "0" : drData["Width_1"].ToString().Replace("*", ""));//W1
                Tw2 = double.Parse(string.IsNullOrEmpty(drData["Width_2"].ToString().Replace("*", "")) ? "0" : drData["Width_2"].ToString().Replace("*", ""));//w2
                Td1 = double.Parse(string.IsNullOrEmpty(drData["Depth_1"].ToString().Replace("*", "")) ? "0" : drData["Depth_1"].ToString().Replace("*", ""));//d1
                Td2 = double.Parse(string.IsNullOrEmpty(drData["Depth_2"].ToString().Replace("*", "")) ? "0" : drData["Depth_2"].ToString().Replace("*", ""));//d2

            }

             //获取单位工时和附加工时
            foreach (var drHours in dr2)
            {
                switch (drHours["OPERATIONAL_NAME"].ToString())
                {
                    case "装洗毛刷板":
                        WD37_Wash_Brush_Board = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_Wash_Brush_Board = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "钻装合页铰":
                        WD37_Drilling_Hinge = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_Drilling_Hinge = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装台面平铰":
                        WD37_Mounted_Countertop_Flat_Hinge = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_Mounted_Countertop_Flat_Hinge = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "打铜头胶塞":
                        WD37_Copper_Head_Rubber_Plug = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_Copper_Head_Rubber_Plug = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "拧带齿螺母":
                        WD37_Twisted_Tooth_Nut = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_Twisted_Tooth_Nut = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装装饰孔盖":
                        WD37_Decorative_Hole_Cover = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_Decorative_Hole_Cover = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "贴美时LOGO":
                        WD37_LOGO = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD37_LOGO = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                }
            }
              //清洗时间
            if (TD37_Wash_Brush_Board != 0 || TD37_Drilling_Hinge != 0 || TD37_Mounted_Countertop_Flat_Hinge != 0 ||
                TD37_Copper_Head_Rubber_Plug != 0 || TD37_Twisted_Tooth_Nut != 0 || TD37_Decorative_Hole_Cover != 0 ||
                TD37_LOGO != 0)
            {
                //工艺路线如果包含D34,则清洗时间为0
                if (Routing.Contains("D34"))
                {
                    TclearHour = 0;
                }
                else
                {
                    TclearHour = (Tw1 * Tw2 * 0.000085 + 4) * 2;
                }
            }
            if (TD37_Wash_Brush_Board > 0)
            {
                if (TD37_Drilling_Hinge > 0)
                {
                    SngH = 20;
                }
                if (TD37_Mounted_Countertop_Flat_Hinge > 0)
                {
                    SngP = 40;
                }

            }
            SngF = SngH + SngP;
            TD37 = TD37_Wash_Brush_Board * (SngF + 65) + 0;//装洗毛刷板工时
            //钻装合页铰工时
            if (TD37_Drilling_Hinge > 0)
            {
                if (NumMAX(Tw1, Tw2) > 1300 || NumMAX(Td1, Td2) > 0)
                {
                    TD37 = TD37 + (35 * TD37_Drilling_Hinge + 40) * 2;
                }
                else
                {
                    TD37 = TD37 + (35 * TD37_Drilling_Hinge + 40) * 1;
                }
            }
            //装台面平铰工时
            if (TD37_Mounted_Countertop_Flat_Hinge > 0)
            {
                TD37 = TD37 + 70 * TD37_Mounted_Countertop_Flat_Hinge;
            }
            //D37_打铜头胶塞
            if (TD37_Copper_Head_Rubber_Plug > 0)
            {
                TD37 = TD37 + 3 * TD37_Copper_Head_Rubber_Plug;
            }
            //拧带齿螺母
            if (TD37_Twisted_Tooth_Nut > 0)
            {
                TD37 = TD37 + 5 * TD37_Twisted_Tooth_Nut;
            }
            //装装饰孔盖
            if (TD37_Decorative_Hole_Cover > 0)
            {
                TD37 = TD37 + 4 * TD37_Decorative_Hole_Cover;
            }
            //LOGO
            if (TD37_LOGO > 0)
            {
                TD37 = TD37 + 10 * TD37_LOGO;
            }
          
            //Total 工时
            TD37 = TD37 + TclearHour;
            return TD37;
        }
        private static double NumMAX(double Tw1, double Tw2)
        {
            if (Tw1 > Tw2)
            {
                return Tw1;
            }
            return Tw2;
        }
    }
}
